<template>
	<BaseContainer>
		<ProjectSelect belongProject="elderlyMeal"></ProjectSelect>
		<aplid-base-crud
			:key="orderType"
			ref="crud"
			class="w-100"
			v-bind="baseConfig"
			:dialogConfig="{ width: dialogWidth }"
			:formConfig="formConfig"
			:operateFormate="operateFormate"
			:paramsObj="{ orderType }"
			:tableConfig="orderType == 1 ? tableConfig1 : tableConfig"
		>
			<template v-slot:menuRight>
				<el-radio-group v-model="orderType">
					<el-radio-button label="配送" :value="1" />
					<el-radio-button label="堂食" :value="0" />
				</el-radio-group>
			</template>
			<template v-slot:orderItemVOListForm="{ model }">
				<MenuCheck
					v-show="model.orderTime"
					:orderTime="model.orderTime"
					v-model="model.orderItemVOList"
					:dish_type_data="dish_type_data"
					style="width: 100%"
				></MenuCheck>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script setup lang="ts">
import ProjectSelect from '@/views/homeCare/components/ProjectSelect/index.vue'
import { baseConfig, editFormConfig, cancelFormConfig, tableConfig1, tableConfig } from './config'
import MenuCheck from './MenuCheck/index.vue'
import apiMod from '@/apiMod/index'
const dish_type_data = ref([])
const orderType = ref(1)
const formConfig: any = ref(baseConfig.formConfig(orderType.value))
const dialogWidth = ref('65%')
const operateFormate = (form, type) => {
	return new Promise((resolve, reject) => {
     if (type == 'edit') {
			dialogWidth.value = '45%'
			form.state = 1
			formConfig.value = editFormConfig
		} else if (type == 'cancel') {
			dialogWidth.value = '45%'
			form.state = 3
			formConfig.value = cancelFormConfig
		} else {
      if(type =='add') form.state = 0
			formConfig.value = baseConfig.formConfig(orderType.value)
			dialogWidth.value = '75%'
		}
		resolve(form)
	})
}

onMounted(() => {
	apiMod.getDictItemList('DISH_TYPE').then((res) => {
		const data = res.data['DISH_TYPE']
		dish_type_data.value = data
	})
})
</script>

<style lang="scss" scoped></style>
